<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML>
<html>
  <head>
  	<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>增加新房间</title>
 	<base href="<%=basePath%>"> 
	<link rel="stylesheet" href="css/bootstrap.css">
    <link rel="stylesheet" href="css/vivo.css">
    <link rel="stylesheet" href="css/cmxform.css">
	<script src="js/jquery-1.11.1.js"></script>
	<script type="text/javascript" src="js/form.js"></script>
    <script src="js/jquery.validation/1.14.0/jquery.validate.min.js"></script>
    <script src="js/jquery.validation/1.14.0/messages_zh.min.js"></script>
    <link href="js/select2/select2.min.css" type="text/css" rel="stylesheet" />
	<script src="js/select2/select2.min.js"></script>
    <script type="text/javascript" src="js/sharefunction.js"></script>
	
   <script type="text/javascript">

   		$.validator.setDefaults({
		    submitHandler: function() {
		      	saveDocument();
		    }
		});
		
		$(document).ready(function() {
			initUploadMulti("<%=basePath %>");
			$("#leaseState").select2({minimumResultsForSearch:-1});
			$("#archiveState").select2({minimumResultsForSearch:-1});
			$("#sortNum").select2({minimumResultsForSearch:-1});
			showRoom();
		    $("#commentForm").validate({
		    	errorPlacement: function(error, element) {
					// Append error within linked label
					$( element ).next().append( error );
				},
				errorElement: "span",
				messages: {
					roomNumber: {
						required: "请填写房间号!"
					},
					unitNumber:{
						required: "请填写单元号!"
					},
					
					coveredArea: {
						number:" 请输入数字！"
					},
					useArea: {
						number:" 请输入数字 ！ "
					}
				}
				
		    });
		});
   		//失去焦点时，验证室号全称是否重复
		function bl(){
			var roomName = $("#roomName").val();
			var buildingInfoId = $("#buildingInfoId").val();
	   		var url = "project/roomInfo/findRoomName";
	   		return onBlur(url,roomName,buildingInfoId);
		}
	   	function saveDocument(){
	   		if(bl()==false){
	   			return;
	   		}
	   	   	var roomNumber = $("#roomNumber").val();
	   	   	var unitNumber = $("#unitNumber").val();
	   	   	var roomName = $("#roomName").val();
	   	   	var floor = $("#floor").val();
	   	 	var coveredArea = $("#coveredArea").val();
	   	 	var useArea = $("#useArea").val();
	   		var orientations = $("#orientations").val();
	   		var fkRoomtype = $("#fkRoomtype").val();
	   		var sortNum = $("#sortNum").val();
	   		var priceSpan = $("#priceSpan").val();
	   		var leaseState = $("#leaseState").val();
	   		var archiveState = $("#archiveState").val();
	   		var archiveReason = $("#archiveReason").val();
	   		var buildingInfoId = $("#buildingInfoId").val();
	 		var deviceRemark = $("#deviceRemark").val();
	 		var attids = $("#attids").val();
			//layer.confirm("确定保存吗？",{icon:3},function(i){
	   			var url = "project/roomInfo/Add";
	   			jQuery.ajax({
					type:"post",
					url:url,
					async:false,
					dataType:"json",
					data:{
						roomNumber:roomNumber,
						unitNumber:unitNumber,
						roomName:roomName,
						floor:floor,
						scoveredArea:coveredArea,
						suseArea:useArea,
						orientations:orientations,
						fkRoomtype:fkRoomtype,
						sortNum:sortNum,
						priceSpan:priceSpan,
						leaseState:leaseState,
						archiveState:archiveState,
						archiveReason:archiveReason,
						buildingInfoId:buildingInfoId,
						deviceRemark:deviceRemark,
						attids:attids
					},success:function(data){
						if(data.success){
							window.parent.layer.msg('保存成功！');
							window.parent.gridObj.refreshPage();
							closeLayer();
						}else{
							layer.alert(data.msg);
						}
					} 
	   	   		});
	   	   	//})
	   	}

		function showPanel(val){
			if(val=="1"){
				$("#panel10").show();
			}else{
				$("#panel10").hide();
			}
		}
		function showRoom(){
			var roomName1 = $("#roomName1").val();
			$("#roomName").val(roomName1+"-")
		}
		function show1(val){
			var roomName1 = $("#roomName1").val();
			var roomNumber = $("#roomNumber").val();
			var unitNumber = $("#unitNumber").val();
			$("#roomName").val(roomName1+"-"+unitNumber+"-"+roomNumber);
			
		}
		function show2(val){
			var roomName1 = $("#roomName1").val();
			var roomNumber = $("#roomNumber").val();
			var unitNumber = $("#unitNumber").val();
			$("#roomName").val(roomName1+"-"+unitNumber+"-"+roomNumber);
		}	
   	
   </script>
  </head>
  
  <body>
  	<form class="cmxform" id="commentForm" method="get" action="">
		<div style="padding:20px">
			<div class="panel panel-default">
				<div class="panel-heading">
      				<h5 class="panel-title">房间信息</h5>
   			  	</div>
	   			<div class="panel-body">
				<table cellpadding="10" cellspacing="5" class="mytable">
					<%--<tr>
						<td width="90" >所属楼栋</td>
					    <td>
					    	<select class="js-example-basic-single" name="buildingInfoId" id="buildingInfoId" style="width:300px;">
						  		<c:forEach var="buildingInfo" items="${buildingInfoList}" varStatus="d">
						  			<option value="${buildingInfo.id}"
						  			<c:if test="${d.index==0}">
							  			selected = "selected"
							  		</c:if>>
							  		${buildingInfo.folderName }</option>
						  		</c:forEach>
						  	</select>
					    </td>
					</tr>
					--%><tr>
		    			<td width="90">房间号</td>
		    			<td width="310">
		    				<input type="text" name="roomNumber" id="roomNumber"  onchange="show1(this.value)"  required /><font color="red"> *</font>
		    				<span></span>
		    			</td>
		    			<td width="90">单元号</td>
		    			<td>
		    				<input type="text" name="unitNumber" id="unitNumber"  onchange="show2(this.value)" class="number" required  onblur="bl()"/><font color="red"> *</font>
		    				<span>如无单元则填写0</span>
		    			</td>
		    		</tr>
		    		<tr>
		    			<td>室号全称</td>
		    			<td><input type="text" name="roomName" id="roomName" value="" readonly/>
		    				<span style="color:red" id="b_tip"></span>
		    				<input type="hidden" name="roomName1" id="roomName1" value="${buildingInfo.buildingNo }">
		    			</td>
		    			<td>所在楼层</td>
		    			<td><input type="text" name="floor" id="floor" />
		    			</td>
		    		</tr>
		    		<tr>
		    			<td>建筑面积</td>
		    			<td><input type="text" name="coveredArea" id="coveredArea" class="number"/> ㎡
		    			<span style="color:red"></span>
		    			</td>
		    			<td>使用面积</td>
		    			<td><input type="text" name="useArea" id="useArea" class="number"/> ㎡
		    			<span style="color:red"></span>
		    			</td>
		    		</tr>
		    		<tr>
		    			<td>朝向</td>
		    			<td><input type="text" name="orientations" id="orientations"/></td>
		    			<td>房型</td>
		    			<td><input type="text" name="fkRoomtype" id="fkRoomtype" placeholder="如：两室一厅/三室一厅"/></td>
		    		</tr>
		    		<tr>
	    				<td>房间性质</td>
	    				<td>
	    				<%--<input type="text" name="sortNum" id="sortNum" placeholder="如：写字楼/商铺/住宅"/>
	    					--%><select name="sortNum" id="sortNum" style="width:80px;">
	    						<option value="0" selected>写字楼</option>
	    						<option value="1">商铺</option>
	    						<option value="2">住宅</option>
	    					</select>
	    				</td>
	    				<td>租售状态</td>
	    				<td>
	    					<select  name="leaseState" id="leaseState" style="width:70px;">
			    				<option value="0" selected>出租</option>
	    						<option value="1">已售</option>
	    					</select>
	    				</td>
	    			</tr>
	    			<tr>
	    				<td>归档状态</td>
	    				<td>
	    					<select name="archiveState" id="archiveState" onchange="showPanel(this.value)" style="width:70px; ">
			    				<option value="0" selected>正常</option>
	    						<option value="1">已归档</option>
	    					</select>
	    				</td>
	    			</tr>
	    			<tr>
	    				<td>设备信息</td>
	    				<td>
	    					<textarea rows="3" cols="32" style="width:178%" name="deviceRemark" id="deviceRemark"></textarea>
	    				</td>
	    			</tr>
	    			<tr>
    				<td>房间平面图</td>
    				<td colspan="3">
    				<input class="uploadify" attType="file1" id="uploadify" name="uploadify" type="file"/><span id="uploadifyInfo" attType="file1"></span>
    				(请上传图片)
    					
    				</td>
    			</tr>
	    			<tr id="panel10" style="display:none">
	    				<td>归档的原因</td>
	    				<td>
	    					<textarea rows="3" cols="32" style="width:178%" name="archiveReason" id="archiveReason"></textarea>
	    				</td>
	    			</tr>
				</table>
				</div>
			</div>
			<div style="width:100%;text-align:center; padding-top:20px"> 
				<button class="btn btn-primary radius" type="submit" > 保 存</button> 
				 <a class="btn btn-default radius" onClick="closeLayer();"> 取 消 </a> 
		    	  <br/><br/>
	    	</div> 
		</div>
		
		
		<div style="display:none">
	    	<input type="text" name="buildingInfoId" id="buildingInfoId" value="${buildingInfo.id }">
	    	<input id="id" name="id" type="hidden" value=""/>
	    </div>
		<jsp:include page="/upload-field.jsp"></jsp:include>
	</form>
  </body>
</html>
